package com.lainiao.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 *  域对象
 *      setAttribute()      设置 域对象
 *      getAttribute()      获取 域对象
 *      removeAttribute()   移除 域对象
 *  请求转发
 *      一次请求
 *          request 作用域 有效
 *          session 作用域 有效
 *  重定向
 *      两次请求
 *          request 作用域 无效
 *          session 作用域 有效
 */
@WebServlet("/ss")
public class session02_SessionScope extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 获取 Session 对象
        HttpSession session = request.getSession();

        // 设置 session 对象
        session.setAttribute("user1","liangFeiFan");
        session.setAttribute("user2","liuXing");
        session.setAttribute("password","123");

        // 移除 session 对象
        session.removeAttribute("password");

        // 设置 request 对象
        request.setAttribute("do","boZui");

//        // 请求转发
//        request.getRequestDispatcher("SessionScope.jsp").forward(request,response);

        // 重定向
        response.sendRedirect("SessionScope.jsp");
    }
}
